import { get, post, del, put } from '../utils/request';
import { ApiResponse, PrivateMessage, PageResult } from '../types';

/**
 * 获取收件箱
 */
export function getInboxMessages(params?: {
  page?: number;
  size?: number;
}) {
  return get<ApiResponse<PageResult<PrivateMessage>>>('/messages/inbox', params);
}

/**
 * 获取发件箱
 */
export function getOutboxMessages(params?: {
  page?: number;
  size?: number;
}) {
  return get<ApiResponse<PageResult<PrivateMessage>>>('/messages/outbox', params);
}

/**
 * 获取消息详情
 */
export function getMessageDetail(messageId: number) {
  return get<ApiResponse<PrivateMessage>>(`/messages/${messageId}`);
}

/**
 * 发送私信
 */
export function sendMessage(data: {
  receiverId?: number;
  receiverUsername?: string;
  subject: string;
  content: string;
}) {
  return post<ApiResponse<PrivateMessage>>('/messages/send', data);
}

/**
 * 标记消息为已读
 */
export function markMessageRead(messageId: number) {
  return put<ApiResponse<string>>(`/messages/${messageId}/read`);
}

/**
 * 删除消息
 */
export function deleteMessage(messageId: number) {
  return del<ApiResponse<string>>(`/messages/${messageId}`);
}

/**
 * 获取未读消息数量
 */
export function getUnreadCount() {
  return get<ApiResponse<number>>('/messages/unread-count');
} 